package io.renren.modules.wx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.wx.dao.BankQuestionDao;
import io.renren.modules.wx.dao.TestDao;
import io.renren.modules.wx.entity.BankQuestionEntity;
import io.renren.modules.wx.service.BankQuestionService;
import io.renren.modules.wx.vo.BankQuestionVo;
import io.swagger.models.auth.In;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("bankQuestionService")
public class BankQuestionServiceImpl extends ServiceImpl<BankQuestionDao, BankQuestionEntity> implements BankQuestionService {

    @Autowired
    TestDao testDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<BankQuestionEntity> page = this.page(
                new Query<BankQuestionEntity>().getPage(params),
                StringUtils.isBlank(key) ? new QueryWrapper<>() :
                        new QueryWrapper<BankQuestionEntity>().eq("bank_id", key)
        );

        return new PageUtils(page);
    }

    @Override
    public List<BankQuestionVo> queryQuestion(Integer testId) {
        List<BankQuestionVo> questionsByTestId = testDao.getQuestionsByTestId(testId);
        return questionsByTestId;
    }

}
